# coding: utf-8
#
# from pyhbase.connection import HBaseConnection
#
#
# '''
# zk：hb-uf6i3710q15t89giw-001.hbase.rds.aliyuncs.com:2181
# thrift访问地址：hb-uf6i3710q15t89giw-001.hbase.rds.aliyuncs.com:9099
# '''
#
# host, port = 'hb-uf6i3710q15t89giw-001.hbase.rds.aliyuncs.com', 9099
# # host, port = 'hb-uf6i3710q15t89giw-001.hbase.rds.aliyuncs.com', 2181
# connection = HBaseConnection(host=host, port=port)

import json
import time
import arrow
import happybase
from concurrent.futures import ThreadPoolExecutor

connection = happybase.Connection('hb-uf6i3710q15t89giw-001.hbase.rds.aliyuncs.com', 9099)

table = happybase.Table(b'news', connection)

start_time = arrow.get("2018-06-29_04-00-00").timestamp
end_time = arrow.get("2018-06-29_07-00-00").timestamp
# query_string = "RowFilter('news', 'actions:timestamp', '1550996664')"

query = table.scan()
for key, data in query:
    print(key)
    print(data)
# # query = table.scan(limit=10)
# file = open('/home/yehun/actions.json', 'a+')
#
#
# def write(string):
#     file.write(string)
#
#
# pool = ThreadPoolExecutor(100)
# all_colums = [
#     b'actions:user_id',
#     b'article:article_id',
#     b'actions:action_id',
#     b'actions:timestamp'
# ]
# for key, data in query:
#     # user_id, time, random_key = key.decode('utf-8').split('_')
#     # print(user_id, time, random_key)
#     flag = False
#     for colums in all_colums:
#         if colums not in data:
#             flag = True
#             break
#     if flag:
#         continue
#     user_id = data[b'actions:user_id'].decode('utf-8')
#     article_id = int(data[b'article:article_id'].decode('utf-8'))
#     timestamp = int(data[b'actions:timestamp'].decode('utf-8'))
#     action_id = int(data[b'actions:action_id'].decode('utf-8'))
#     string = '%s|%s|%s|%s\n' % (user_id, article_id, action_id, timestamp)
#     # file.write(string)
#     # pool.submit(write, string)
#     # print(arrow.get(int(data[b'actions:timestamp'])).format('YYYY-MM-DD HH:mm:ss.SSS'))
#     print(string)
# pool.shutdown()
# file.close()

